package com.dkd.http.controller;

import com.dkd.entity.SkuEntity;
import com.dkd.entity.dto.VmPageDto;
import com.dkd.entity.vo.SkuPageVo;
import com.dkd.entity.vo.SkuVo;
import com.dkd.service.SkuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * 商品管理
 */
@RestController
@RequestMapping("/sku")
@Api(tags = "商品业务")
@Slf4j
@RequiredArgsConstructor
public class SkuController {
    private final SkuService skuService;
    @GetMapping("/businessTop10/{businessId}")
    @ApiOperation("获取商圈下销量前10的商品")
    public List<SkuVo> getTop10(@PathVariable("businessId") Long businessId){
        return skuService.getTop10(businessId);
    }
    @PutMapping("/{skuId}")
    @ApiOperation("修改商品")
    public boolean updateSku(@RequestBody SkuEntity skuEntity){
        return skuService.updateById(skuEntity);
    }
    @PostMapping("/upload")
    @ApiOperation("商品数据导入")
    public void upload(@RequestParam String fileName) throws IOException {
        skuService.upload(fileName);
    }

    @GetMapping("/search")
    @ApiOperation("商品搜索")
    public SkuPageVo searchSku(VmPageDto vmPageDto){
        return skuService.searchSku(vmPageDto);
    }
    @ApiOperation("新增商品")
    @PostMapping
    public boolean AddSku(@RequestBody SkuEntity skuEntity){
        return skuService.save(skuEntity);
    }
    @DeleteMapping("/{skuId}")
    @ApiOperation("删除商品类型")
    public boolean DeleteSkuClass(@PathVariable("skuId") Integer skuId){
        return skuService.removeById(skuId);
    }
}